//
//  NSLayoutConstraint+LTOVE.m
//  LTOVECustom
//
//  Created by LTOVE on 2017/1/24.
//  Copyright © 2017年 LTOVE. All rights reserved.
//

#import "NSLayoutConstraint+LTOVE.h"

@implementation NSLayoutConstraint (LTOVE)

+ (instancetype)reConstraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c{
    UIView *views = (UIView *)view1;
    views.translatesAutoresizingMaskIntoConstraints = NO;
    for (NSLayoutConstraint *consts in views.superview.constraints) {
        if ([consts.firstItem isEqual:view1] && consts.firstAttribute == attr1) {
            [views.superview removeConstraint:consts];
        }
    }
    return [NSLayoutConstraint constraintWithItem:view1 attribute:attr1 relatedBy:relation toItem:view2 attribute:attr2 multiplier:multiplier constant:c];
    
}


+ (void)reMoveAllConstWithItem:(UIView *)view{
    for (NSLayoutConstraint *consts in view.superview.constraints) {
        if ([consts.firstItem isEqual:view]) {
            [view.superview removeConstraint:consts];
        }
    }
}
+ (void)addConstWith:(UIView *)views twoView:(UIView *)twoView top:(CGFloat)top left:(CGFloat)left Bottom:(CGFloat)Bottom right:(CGFloat)right width:(CGFloat)width height:(CGFloat)height{
    
    [views.superview addConstraint:[NSLayoutConstraint reConstraintWithItem:views attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:twoView attribute:NSLayoutAttributeTop multiplier:1.0 constant:top]];
    [views.superview addConstraint:[NSLayoutConstraint reConstraintWithItem:views attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:twoView attribute:NSLayoutAttributeTop multiplier:1.0 constant:top]];
    [views.superview addConstraint:[NSLayoutConstraint reConstraintWithItem:views attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:twoView attribute:NSLayoutAttributeTop multiplier:1.0 constant:top]];
    [views.superview addConstraint:[NSLayoutConstraint reConstraintWithItem:views attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:twoView attribute:NSLayoutAttributeTop multiplier:1.0 constant:top]];
    [views.superview addConstraint:[NSLayoutConstraint reConstraintWithItem:views attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:twoView attribute:NSLayoutAttributeTop multiplier:1.0 constant:top]];
    
    
}
@end
